package  {
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import fs.tileMap.view.tile.AbstractTile;
	
	/**
	 * ...
	 * @author flyingSnow
	 */
	public class MyMapTile extends AbstractTile {
		private var _bg:Sprite;
		private var _tf:TextField;
		
		public function MyMapTile() {
			super();
			draw();
		}
		
		private function draw():void {
			_bg = new Sprite();
			addChild(_bg);
			_bg.graphics.lineStyle(1);
			_bg.graphics.beginFill(0xcccccc);
			_bg.graphics.drawRect(0, 0, 40, 40);
			_bg.graphics.endFill();
			
			_tf = new TextField();
			_tf.mouseEnabled = false;
			_tf.defaultTextFormat = new TextFormat(null, 16);
			_tf.x = 1;
			_tf.y = -1;			
			addChild(_tf);
		}
		override protected function render(code:int):void {
			//_tf.text = code+"";
			var color:int = code;
			var redOffset:int = color >> 16;
			var greenOffset:int = (color >> 8)&0xff;
			var blueOffset:int = color&0xff;
			_bg.transform.colorTransform = new ColorTransform(0, 0, 0, 1, redOffset, greenOffset, blueOffset);
		}
		override public function getTileWidth():uint {
			return 40;
		}
		override public function getTileHeight():uint {
			return 40;
		}
		
		public function get text():String {
			return _tf.text;
		}
		public function set text(value:String):void {
			_tf.text = value;
		}
	}

}